var _regions = new Array();
_regions[0] = "ef_region_inqu";
_regions[1] = "ef_region_result";
_regions[2] = "ef_region_mainadd";
_regions[3] = "ef_region_solveadd";
_regions[4] = "ef_region_feedbackreport";
_regions[5] = "ef_region_report";
var fdTccrId;
efform_onload = function() {
	
	
//	InitRegionShow();
	hideAllRegions(_regions);
	$('#ef_region_inqu').show();
	$('#ef_region_result').show();
	$('#ef_region_mainadd').show();
	$('#ef_region_feedbackreport').hide();
	$('#ef_region_solveadd').hide();
	
	// efgrid.submitInqu( "ef_grid_r", "ZM","ZMCC11","query");
//	 var info = new EiInfo();
//	 info.set("fdTccrId",fdTccrId); 
	// EiCommunicator.send("ZMCC13", "query", _info, ajax_select_callback);
	// EiCommunicator.send("ZMCC14", "query", _info, ajax_select_callback1);
	var info = new EiInfo();
	EiCommunicator.send("ZMCK01", "query", info, ajax_callback1);
};
var ajax_callback1 = {
	onSuccess : function(eiInfo) {
		efwindow.hide();
		var grid = efgrid.getGridObject("ef_grid_feedbackreport");
		grid.refresh(eiInfo);
	},
	onFail : function(eMsg) {
	}
};
function InitRegionShow() {
	hideAllRegions(_regions);
	$('#ef_region_inqu').show();
	$('#ef_region_result').show();
	$('#ef_region_mainadd').show();
	$('#ef_region_feedbackreport').show();
}

/* 根据主表查询明细 */
efgrid_onRowClicked = function(grid_id, row_index) {
	if (grid_id == "ef_grid_result") {
		var grid = efgrid.getGridObject(grid_id);
		var selectedRow = grid.getRowData(row_index);
	    fdTccrId=grid.getCellValueByColumnName(row_index,"fdKeyId");
//		alert(fdTccrId);
		for (var item in selectedRow) {
			var colname = item;
			var colvalue = selectedRow[item];
			$('#ef_region_mainadd').find('#result_add-0-' + colname).val(colvalue);
			// $('#ef_region_solveadd').find('#solve_add-0-'+colname).val(colvalue);
		}
		var info = new EiInfo();
		info.set("fdTccrId",fdTccrId); 
		InitRegionShow();
		EiCommunicator.send("ZMCK01", "query", info, ajax_callback1);  
	}
};
var ajax_callback1 = {
		onSuccess : function(eiInfo) {
			var grid = efgrid.getGridObject("ef_grid_feedbackreport");
			grid.refresh(eiInfo);
		},
		onFail : function(eMsg) {
			alert("确认失败，原因：" + eMsg);
		}

	}
var ajax_callback = {
	onSuccess : function(eiInfo) {
		var grid = efgrid.getGridObject("ef_grid_result");
		grid.refresh(eiInfo);
		clearAfterSolve("ef_region_mainadd");
	},
	onFail : function(eMsg) {
		alert("确认失败，原因：" + eMsg);
	}

}
button_insert_onclick = function (){
	check();
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info) {
		EiCommunicator.send("ZMCK00", "insert", info, ajax_callback);
	}
}



button_update_onclick = function (){
	check();
	var status=$('#result_add-0-fdStatus').val();
	
	var info = getDetail("ef_region_mainadd","result_add");
	if (null != info && status == "草拟") {
		EiCommunicator.send("ZMCK00", "update", info, ajax_callback);
	}else{
		EFAlert("只能对草拟的记录进行修改！"); return;
	} 
}

button_query_onclick = function (){
	efgrid.submitInqu( "ef_grid_result", "ZM","ZMCK00","query");
}
button_delete_onclick = function (){
	var grid=isSelected("ef_grid_result");
	if (grid == 0)return; 
	var rows=grid.getCheckedRows();
	for(var i=0;i<rows.length;i++)
	{
		if(grid.getCellValueByColumnName(rows[i],"fdStatus")!="草拟")
		{
			EFAlert("只能对草拟的记录进行删除！"); return;
		}
	}
	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK00","delete",true);
	}); 
}


button_report_onclick = function (){
	if (isSelected("ef_grid_result") == 0)
		return; 
	EFConfirm('你确认要上报吗?', '确认框', function(r) {
		if(r)efgrid.submitForm( "ef_grid_result", "ZM","ZMCK00","report",true);
	}); 
}


/*******************************************************************************
 * ************************************************************************
 * 停产撤人方案信息 方法
 * ************************************************************************
 ******************************************************************************/
button_close_onclick = function ()//CLOSE 关闭 
{
 	
	var grid=isSelectedOne("ef_grid_result");
	if (grid == 0)return; 
	var selectedRow=grid.getSelectRowsData()[0]; 

	for(var item in selectedRow){
		var colname=item;
		var colvalue=selectedRow[item];
		$('#solve_add-0-'+colname).val(colvalue); 
		$('#result_add-0-'+colname).val(colvalue); 
		var status=$('#result_add-0-fdStatus').val();
	} 

	if(status != "关闭"){
	 hideAllRegions(_regions);
		$('#ef_region_solveadd').show();
	}
	else{
		EFAlert("已关闭！"); 
		return;
	}
} 



button_solveconfirm_onclick = function ()//CLOSE 主表 确定
{
//	if(efvalidateDiv("ef_region_solveadd")){
		var info = getDetail("ef_region_solveadd","solve_add");
		if (null != info) {
			EiCommunicator.send("ZMCK00", "close", info, ajax_solveconfirm_callback);
		} 
//	}
	InitRegionShow();
} 
var ajax_solveconfirm_callback= {
	onSuccess: function(eiInfo) {
		var grid = efgrid.getGridObject("ef_grid_result");
		grid.refresh(eiInfo);//刷新主表grid
	},
	onFail:function(eMsg)
	{
		alert("确认失败，原因："+eMsg); 
	}
}

button_solvecancel_onclick = function ()//CLOSE 主表 返回
{
	InitRegionShow();
} 


/*******************************************************************************
 * ************************************************************************
 * 停产撤人方案反馈 方法
 * ************************************************************************
 ******************************************************************************/
button_feedback_onclick = function()// FEEDBACK 反馈
{

	var grid = isSelectedOne("ef_grid_feedbackreport");
	if (grid == 0)
		return;
	var selectedRow = grid.getSelectRowsData()[0];

	for ( var item in selectedRow) {
		var colname = item;
		var colvalue = selectedRow[item];
		$('#report-0-' + colname).val(colvalue);
	}

	hideAllRegions(_regions);
	$('#ef_region_report').show();

}

button_reportconfirm_onclick = function()// FEEDBACK 确定
{
	// if(efvalidateDiv("ef_region_solveadd")){
	
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('report').getRows(0)[0][4]==""){
		EFAlert("停产撤人执行情况不能为空");
		return;
	}
	var info = getDetail("ef_region_report", "report");
	info.set("fdTccrId",fdTccrId); 
	if (null != info) {
		EiCommunicator.send("ZMCK01", "insert", info,
				ajax_reportconfirm_callback);
	}
	// }
	InitRegionShow();
}
var ajax_reportconfirm_callback = {
	onSuccess : function(eiInfo) {
		var grid = efgrid.getGridObject("ef_grid_feedbackreport");
		grid.refresh(eiInfo);// 刷新
//		efform_onload();

	},
	onFail : function(eMsg) {
		alert("确认失败，原因：" + eMsg);
	}
}

button_reportcancel_onclick = function()// FEEDBACK 返回
{
	InitRegionShow();
}

button_delete1_onclick = function() {
	var grid = isSelected("ef_grid_feedbackreport");
	if (grid == 0)
		return;
	var rows = grid.getCheckedRows();

	EFConfirm('你确认要删除吗?', '确认框', function(r) {
		if (r)
//		var info = getDetail("ef_region_report", "report");
//		info.set("fdTccrId",fdTccrId); 
//		if (null != info) {
//			EiCommunicator.send("ZMCK01", "delete", info,
//					ajax_reportconfirm_callback);
//		}
			
			
			efgrid.submitForm("ef_grid_feedbackreport", "ZM", "ZMCK01",
					"delete", true);
	});
}


efgrid_afterAddNewRow = function(grid_id){ 
	var grid = efgrid.getGridObject(grid_id);
	var rows = grid.getCheckedRows(); 
	if(grid_id=="ef_grid_feedbackreport")
	{		
		var fdDepartment=$('#fdCreateDepartment').val();		
		var fdDepartmentId=$('#fdCreateDepartmentId').val();	  
	   
		for(var i = 0 ; i < rows.length;i++){		
//			grid.setCellValue(rows[i],5,fdCreateDepartment,TYPE_DATA); 
//			grid.setCellValue(rows[i],1,fdDepartmentId,TYPE_DATA); 
			grid.setCellValue(rows[i],1,fdDepartment,TYPE_DATA); 
			
//			grid.setCellValue(rows[i],6,fdCreateDepartment,TYPE_DATA); 
		}
	}
}

/**
 * 操作完成后清空该region内的各数据项的值
 */
var clearAfterSolve=function(region) { 
	var temp;
	//遍历INPUT
	$('#'+region).find("input").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
//		$(this).removeData();
	});
	//遍历SELECT
	$('#'+region).find("select").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
	//遍历TEXTAREA
	$('#'+region).find("textarea").each(function (){
		temp = $(this).attr("id");
		$('#'+temp).val("");
	});
};

/**
 * 非空校验
 */
check = function()
{
	var ei_info=new EiInfo();
	ei_info.setByNodeObject(document.forms[0]); 
	if(ei_info.getBlock('result_add').getRows(0)[0][2]==""){
		EFAlert("汇报时间不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][3]==""){
		EFAlert("汇报人不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][4]==""){
		EFAlert("停产撤人方案名称不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][6]==""){
		EFAlert("停产撤人实施方案不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][7]==""){
		EFAlert("停产撤人应急预案不能为空");
		return;
	}
	if(ei_info.getBlock('result_add').getRows(0)[0][8]==""){
		EFAlert("停产撤人避灾路线不能为空");
		return;
	}
}